package com.hjimi.ski.view.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hjimi.ski.R;
import com.white.progressview.HorizontalProgressView;

/**
 * Created By 孙岩
 * on 2023/12/19
 */
public class ProgressDialog extends Dialog {
    private String mText;//弹窗中间文字显示
    private HorizontalProgressView mProgresBar;//
    private TextView mTvTotal;//文件大小

    public ProgressDialog(@NonNull Context context) {
        super(context);
        init();
    }
    /**
     * 用户可以自定义的设置中间显示的提示语
     *
     * @param mText
     */
    public void setmText(String mText) {
        this.mText = mText;
        if (mTvTotal != null) {
            mTvTotal.setText("文件总大小：" + mText );
        }
    }

    private void init() {
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(getOwnerActivity().LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.download_dialog,
                null);
        mTvTotal = view.findViewById(R.id.tv_total);
        mProgresBar = view.findViewById(R.id.progress100);
        setContentView(view);
        getWindow().setGravity(Gravity.CENTER);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    public void setProgress(int pro){
        mProgresBar.setProgress(pro);
    }

    public void dismissProgress(){
        dismiss();
    }
}
